﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Data;

namespace Daq.Converters
{
    internal class DaqWorkStatusToStringConverter : IValueConverter
	{
		public static string GetDescription(Enum obj)
		{
			if (obj == null)
				return "";

			var type = obj.GetType();
			var enumName = Enum.GetName(type, obj);
			var field = type.GetField(enumName);
			var val = (int)field.GetValue(null);
			var atts = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
			if (atts != null && atts.Length > 0)
			{
				var att = ((DescriptionAttribute[])atts)[0];
				return att.Description;
			}
			return "";
		}
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			//if (value is DaqWorkStatus status)
			//{
			//	return GetDescription(status);
			//}
			return "";
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
